const router = require('koa-router')();
const cc = require('../conCtl');
const js = require('../jsCtl');
const db = require('../dbCtl');

/**
@hostpath = http://127.0.0.1/client/message
 */

/** 
###
    GET {{hostpath}}?openid=oM2uY50rohAiNnksjCvt0HknGDAo&page=1&size=10
### */
router.get('/', async c => {
  js.check_params(
    !c.query.openid && '!用户ID');
  let
  page = c.query.page || 1,
  size = c.query.size || 10;

  let data = await db.model('t_message')
    .where('openid=?', c.query.openid)
    .orderBy('dt desc')
    .select(page,size);
  cc.send(c, data);
});


module.exports = router;